<template>

</template>
<script>
import wepy from 'wepy'
import SwipeDelete from './common/wepy-swipe-delete'
import tip from '@/utils/tip'
import api from "@/api/api";
import {
  USER_SPECICAL_INFO,
  ADDRESS_ID
} from '@/utils/constant';
export default class AddressList extends wepy.component {
  props = {
    addressList: {
      default: [{
        style: 0
      }, {
        style: 0
      }],
      type: Object
    }
  }
  components = {
    swipeDelete: SwipeDelete
  }

  data = {
    receiverInfo:{},
    type: ""
  }

  async delUserAddress(id) {
    let that = this;
    let userSpecialInfo = wepy.getStorageSync(USER_SPECICAL_INFO) || {};
    const json = await api.delUserAddress({
      query: {
        id: id,
        type:2
      }
    });

    if (json.data.code == 0) {
      console.log("删除成功");
      this.$emit('currentPage', 0);
      this.$emit('refreshAddList', 'hehe');
    } else {
      tip.error(json.data.msg)
    }
    that.showLoading = false;
  }
  methods = {
    add() {
      //0 列表 1新增 2编辑
      this.$emit('currentPage', 1);
    },
    edit(e) {
      var id = e.currentTarget.dataset.id;
      //0 列表 1新增 2编辑
      this.$emit('currentPage', 2,id);
    },
    //左滑删除
    handleDelItem(itemData) {
      this.delUserAddress(itemData.id);
      console.log("左滑删除")
      console.log(itemData.id)

    },

    refreshList(val){
      if (val==undefined) return;
      console.log("val.....",val);
      this.addressList = val;
      this.$apply();
    },

    setOrgType (type) {
      this.type=type;
    },

    tapSelAddress(e) {
      if (this.type!="order") {
        return;
      }
      var id = e.currentTarget.dataset.id;
      console.log("id=="+id);
      wepy.setStorageSync(ADDRESS_ID,id);
      wepy.redirectTo({
        url: "/pages/comfire_order?from=selAdd"
      })
    }
  }

  onLoad() {

  }
}

</script>
<style lang="less">
.list_box {
  height: 150rpx;
}

.address {
  .list_box:last-child {
    border-bottom: 1px solid #efefef;
  }
  .address_list {
    display: flex;
    justify-content: space-between;
    height: 150rpx;
    align-items: center;
    padding: 0rpx 0px 0px 35rpx;
    border-top: 1px solid #efefef;
    .title {
      color: #000;
    }
    .arrow {
      height: 150rpx;
      line-height: 150rpx;
      width: 150rpx;
      text-align: center;
      color: #9a9a9a;
    }
    .user_info {
      color: #1a1a1a;
    }
    .active_address {
      margin-top: 20rpx;
    }
    .defult {
      color: #ea4a3a;
    }
  }
}

.add_wrap {
  display: block;
  width: 95%;
  left: 0;
  right: 0;
  position: absolute;
  bottom: 20rpx;
  margin: 0 auto;
}

</style>
